//==========================================================
// 此代码由TilverNET代码生成工具自动生成，请不要修改
// 代码生成器版本号：1.2
// 作者：landy
// 联系方式：(QQ)86566178
// 创建时间：2014/6/21 10:58:22
//==========================================================

using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Linq;
using Tilver.Data;
using Tilver.Data.DataPager;

namespace Weixin.MP.DAL.WeixinMP
{
	#region EO

	/// <summary>
	/// 响应消息日志 《dbo.ResponseMessageLog(实体类)》
	/// </summary>
	[Serializable]
	public class ResponseMessageLogEO : IRowMapper<ResponseMessageLogEO>
	{
		protected bool _hasOriginal = false;
		protected long _respId;
		protected long _originalRespId;
		protected string _msgType;
		protected string _toUser;
		protected string _fromUser;
		protected DateTime? _createTime;
		protected string _respXml;
		protected DateTime? _respTime;

		/// <summary>
		/// 主键是否有原始值（即数据库中保存的值），用于实体对象更新时
		/// </summary>
		public bool HasOriginal
		{
			get { return _hasOriginal; }
		}


		/// <summary>
		/// 日志ID 《[主键]  [bigint]   自增字段》
		/// </summary>
		public long RespId
		{
			get { return _respId; }
			set { _respId = value;}
		}

		/// <summary>
		/// 日志ID 《数据库中的原始主键值副本》
		/// </summary>
		public long OriginalRespId
		{
			get { return _originalRespId; }
			set { 
				_hasOriginal = true;
				_originalRespId = value;
			}
		}

		/// <summary>
		/// 消息类型 《[字段]  [varchar]》
		/// </summary>
		public string MsgType
		{
			get { return _msgType; }
			set { _msgType = value;}
		}

		/// <summary>
		/// 接收用户 《[字段]  [varchar]》
		/// </summary>
		public string ToUser
		{
			get { return _toUser; }
			set { _toUser = value;}
		}

		/// <summary>
		/// 来源用户 《[字段]  [varchar]》
		/// </summary>
		public string FromUser
		{
			get { return _fromUser; }
			set { _fromUser = value;}
		}

		/// <summary>
		/// 创建时间 《[字段]  [datetime]》
		/// </summary>
		public DateTime? CreateTime
		{
			get { return _createTime; }
			set { _createTime = value;}
		}

		/// <summary>
		/// 响应文本 《[字段]  [nvarchar]》
		/// </summary>
		public string RespXml
		{
			get { return _respXml; }
			set { _respXml = value;}
		}

		/// <summary>
		/// 响应文本 《[字段]  [datetime]》
		/// </summary>
		public DateTime? RespTime
		{
			get { return _respTime; }
			set { _respTime = value;}
		}

		/// <summary>
		/// 默认构造函数
		/// </summary>
		public ResponseMessageLogEO() 
		{
			RespTime = DateTime.Now;
		}

		/// <summary>
		/// 自定义构造函数
		/// </summary>
		/// <param name = "respId">日志ID</param>
		/// <param name = "msgType">消息类型</param>
		/// <param name = "toUser">接收用户</param>
		/// <param name = "fromUser">来源用户</param>
		/// <param name = "createTime">创建时间</param>
		/// <param name = "respXml">响应文本</param>
		/// <param name = "respTime">响应文本</param>
		public ResponseMessageLogEO(long respId, string msgType, string toUser, string fromUser, DateTime? createTime, string respXml, DateTime? respTime) 
		{
			_respId = respId;
			_msgType = msgType;
			_toUser = toUser;
			_fromUser = fromUser;
			_createTime = createTime;
			_respXml = respXml;
			_respTime = respTime;
		}


		/// <summary>
		/// 将结果集映射成实体对象
		/// </summary>
		/// <param name = "reader">只进结果集流</param>
		/// <return></return>
		public ResponseMessageLogEO MapRow(IDataReader reader)
		{
			var ret = new ResponseMessageLogEO();
			ret.RespId = (long)reader["RespId"];
			ret.OriginalRespId = ret.RespId;
			ret.MsgType = (reader["MsgType"] is DBNull) ? null : (string)reader["MsgType"];
			ret.ToUser = (reader["ToUser"] is DBNull) ? null : (string)reader["ToUser"];
			ret.FromUser = (reader["FromUser"] is DBNull) ? null : (string)reader["FromUser"];
			ret.CreateTime = (reader["CreateTime"] is DBNull) ? null : (DateTime?)reader["CreateTime"];
			ret.RespXml = (reader["RespXml"] is DBNull) ? null : (string)reader["RespXml"];
			ret.RespTime = (reader["RespTime"] is DBNull) ? null : (DateTime?)reader["RespTime"];
			return ret;
		}

		/// <summary>
		/// 将结果集映射成实体对象，返回映射方法
		/// </summary>
		/// <return></return>
		public Func<IDataReader, ResponseMessageLogEO> GetMapper()
		{
			return MapRow;
		}


	}


	#endregion
	#region MO

	/// <summary>
	/// 响应消息日志 《dbo.ResponseMessageLog(逻辑类)》
	/// </summary>
	public class ResponseMessageLogMO : DbManagerBase
	{

		#region 构造函数
		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name = "routeData">路由数据</param>
		public ResponseMessageLogMO(object routeData = null) : base(routeData) { }

		/// <summary>
		/// 构造函数
		/// </summary>
		/// <param name = "connectionStringName">连接字符串名称</param>
		public ResponseMessageLogMO(string connectionStringName) : base(connectionStringName) { }

		#endregion

		#region 私有方法
		/// <summary>
		/// 数据库访问操作方法
		/// </summary>
		/// <param name = "sql">SQL语句</param>
		/// <return>返回数据操作对象</return>
		private DbAdoBase AdoBase(string sql)
		{
			return DataBase.CreateDbAdo(sql, CommandType.Text);
		}

		#endregion

		#region Select方法集合
		/// <summary>
		/// 按主键查询
		/// </summary>
		/// <param name = "respId">日志ID</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public ResponseMessageLogEO SelectByPK(long respId, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			sql.AppendFormat(@"SELECT [RespId], [MsgType], [ToUser], [FromUser], [CreateTime], [RespXml], [RespTime] FROM [dbo].[ResponseMessageLog] WHERE [RespId]=@RespId ");
			return AdoBase(sql.ToString())
							.AddInParameter("@RespId", respId, DbType.Int64, 8)
							.ExecuteReader(tm).MapToSingle(new ResponseMessageLogEO().GetMapper());
		}


		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "respId">日志ID</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<ResponseMessageLogEO> SelectByRespId(long respId, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [RespId], [MsgType], [ToUser], [FromUser], [CreateTime], [RespXml], [RespTime] FROM [dbo].[ResponseMessageLog] WHERE [RespId]=@RespId");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@RespId", respId, DbType.Int64, 8)
							.ExecuteList(new ResponseMessageLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "msgType">消息类型</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<ResponseMessageLogEO> SelectByMsgType(string msgType, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [RespId], [MsgType], [ToUser], [FromUser], [CreateTime], [RespXml], [RespTime] FROM [dbo].[ResponseMessageLog] WHERE [MsgType]=@MsgType");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@MsgType", msgType, DbType.AnsiString, 20)
							.ExecuteList(new ResponseMessageLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "toUser">接收用户</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<ResponseMessageLogEO> SelectByToUser(string toUser, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [RespId], [MsgType], [ToUser], [FromUser], [CreateTime], [RespXml], [RespTime] FROM [dbo].[ResponseMessageLog] WHERE [ToUser]=@ToUser");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@ToUser", toUser, DbType.AnsiString, 100)
							.ExecuteList(new ResponseMessageLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "fromUser">来源用户</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<ResponseMessageLogEO> SelectByFromUser(string fromUser, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [RespId], [MsgType], [ToUser], [FromUser], [CreateTime], [RespXml], [RespTime] FROM [dbo].[ResponseMessageLog] WHERE [FromUser]=@FromUser");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@FromUser", fromUser, DbType.AnsiString, 100)
							.ExecuteList(new ResponseMessageLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "createTime">创建时间</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<ResponseMessageLogEO> SelectByCreateTime(DateTime? createTime, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [RespId], [MsgType], [ToUser], [FromUser], [CreateTime], [RespXml], [RespTime] FROM [dbo].[ResponseMessageLog] WHERE [CreateTime]=@CreateTime");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@CreateTime", createTime, DbType.DateTime, 8)
							.ExecuteList(new ResponseMessageLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "respXml">响应文本</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<ResponseMessageLogEO> SelectByRespXml(string respXml, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [RespId], [MsgType], [ToUser], [FromUser], [CreateTime], [RespXml], [RespTime] FROM [dbo].[ResponseMessageLog] WHERE [RespXml]=@RespXml");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@RespXml", respXml, DbType.String, -1)
							.ExecuteList(new ResponseMessageLogEO().GetMapper(), tm);
		}
		/// <summary>
		/// 按字段查询
		/// </summary>
		/// <param name = "respTime">响应文本</param>
		/// <param name = "top">获取记录数，当top值小于或等于0时忽略top条件</param>
		/// <param name = "sort">排序表达式，如：field1 ASC,field2 DESC</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<ResponseMessageLogEO> SelectByRespTime(DateTime? respTime, int top, string sort, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [RespId], [MsgType], [ToUser], [FromUser], [CreateTime], [RespXml], [RespTime] FROM [dbo].[ResponseMessageLog] WHERE [RespTime]=@RespTime");
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddInParameter("@RespTime", respTime, DbType.DateTime, 8)
							.ExecuteList(new ResponseMessageLogEO().GetMapper(), tm);
		}

		/// <summary>
		/// 按自定义条件查询
		/// </summary>
		/// <param name = "where">自定义条件,where子句</param>
		/// <param name = "top">获取行数</param>
		/// <param name = "sort">排序表达式</param>
		/// <param name = "paras">where子句中定义的参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public List<ResponseMessageLogEO> Select(string where, int top, string sort, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			var sql = new StringBuilder();
			var format = new StringBuilder();
			format.Append(@"SELECT {0} [RespId], [MsgType], [ToUser], [FromUser], [CreateTime], [RespXml], [RespTime] FROM [dbo].[ResponseMessageLog] ");
			if (!string.IsNullOrEmpty(where)) format.AppendFormat(" WHERE {0} ", where);
			if (!string.IsNullOrEmpty(sort)) format.AppendFormat(" ORDER BY {0} ", sort);
			sql.AppendFormat(format.ToString(), (top > 0) ? string.Format("TOP {0}", top) : string.Empty);
			return AdoBase(sql.ToString())
							.AddParameters(paras)
							.ExecuteList(new ResponseMessageLogEO().GetMapper(), tm);
		}

		/// <summary>
		/// 分页查询
		/// </summary>
		/// <param name = "where">条件表达式</param>
		/// <param name = "sort">排序表达式</param>
		/// <param name = "paras">传入参数</param>
		/// <param name = "pageSize">页大小</param>
		/// <param name = "pageIndex">页码</param>
		/// <param name = "recordCount">总记录数，由于计算总记录数影响数据库性能，只有小于或等于0的情况下才返回总记录数</param>
		/// <return>分页数据</return>
		public List<ResponseMessageLogEO> SelectPager(string where, string sort, IList<DbParameter> paras, long pageSize, long pageIndex, ref long recordCount)
		{
			var sql = new StringBuilder();
			sql.AppendFormat(@"SELECT [RespId], [MsgType], [ToUser], [FromUser], [CreateTime], [RespXml], [RespTime] FROM [dbo].[ResponseMessageLog]");
			if (!string.IsNullOrEmpty(where)) sql.AppendFormat(" WHERE {0} ", where);
			if (!string.IsNullOrEmpty(sort)) sql.AppendFormat(" ORDER BY {0} ", sort);
			var pager = this.DataBase.CreatePager(sql.ToString(), pageSize, "RespId");
			pager.AddParameters(paras);
			if (recordCount <= 0)
			{
				recordCount = pager.GetRecordCount();
			}
			return pager.GetPageData(pageIndex).MapToList(new ResponseMessageLogEO().GetMapper());
		}

		#endregion

		#region Insert方法集合
		/// <summary>
		/// 插入数据，有自增列时，item中自增字段为新增值，否则，返回影响的行数
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "item">要插入的实体对象</param>
		/// <return></return>
		public int Insert(ResponseMessageLogEO item, TransactionManager tm = null)
		{
			const string sql = @"INSERT INTO [dbo].[ResponseMessageLog] ([MsgType], [ToUser], [FromUser], [CreateTime], [RespXml], [RespTime]) VALUES (@MsgType, @ToUser, @FromUser, @CreateTime, @RespXml, @RespTime) ;SELECT SCOPE_IDENTITY();";
			item.RespId = long.Parse(AdoBase(sql)
												.AddInParameter("@MsgType", item.MsgType != null ?  (object)item.MsgType : DBNull.Value, DbType.AnsiString, 20)
												.AddInParameter("@ToUser", item.ToUser != null ?  (object)item.ToUser : DBNull.Value, DbType.AnsiString, 100)
												.AddInParameter("@FromUser", item.FromUser != null ?  (object)item.FromUser : DBNull.Value, DbType.AnsiString, 100)
												.AddInParameter("@CreateTime", item.CreateTime.HasValue ? (object)item.CreateTime.Value : DBNull.Value, DbType.DateTime, 8)
												.AddInParameter("@RespXml", item.RespXml != null ?  (object)item.RespXml : DBNull.Value, DbType.String, -1)
												.AddInParameter("@RespTime", item.RespTime.HasValue ? (object)item.RespTime.Value : DBNull.Value, DbType.DateTime, 8)
												.ExecuteScalar(tm).ToString());
			return 1;
		}
		#endregion

		#region Update方法集合
		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "item">要更新的实体对象</param>
		/// <param name = "tm">事务管理对象</param>
		/// <return></return>
		public int Update(ResponseMessageLogEO item, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[ResponseMessageLog] SET [MsgType]=@MsgType, [ToUser]=@ToUser, [FromUser]=@FromUser, [CreateTime]=@CreateTime, [RespXml]=@RespXml, [RespTime]=@RespTime WHERE [RespId]=@OriginalRespId";
			return AdoBase(sql)
							.AddInParameter("@OriginalRespId", (item.HasOriginal) ? item.OriginalRespId : item.RespId, DbType.Int64, 8)
							.AddInParameter("@MsgType", item.MsgType != null ?  (object)item.MsgType : DBNull.Value, DbType.AnsiString, 20)
							.AddInParameter("@ToUser", item.ToUser != null ?  (object)item.ToUser : DBNull.Value, DbType.AnsiString, 100)
							.AddInParameter("@FromUser", item.FromUser != null ?  (object)item.FromUser : DBNull.Value, DbType.AnsiString, 100)
							.AddInParameter("@CreateTime", item.CreateTime.HasValue ? (object)item.CreateTime.Value : DBNull.Value, DbType.DateTime, 8)
							.AddInParameter("@RespXml", item.RespXml != null ?  (object)item.RespXml : DBNull.Value, DbType.String, -1)
							.AddInParameter("@RespTime", item.RespTime.HasValue ? (object)item.RespTime.Value : DBNull.Value, DbType.DateTime, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "respId">日志ID</param>
		/// <param name = "msgType">消息类型</param>
		/// <return></return>
		public virtual int UpdateMsgType(long respId, string msgType)
		{
			return UpdateMsgType(respId, msgType, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "respId">日志ID</param>
		/// <param name = "msgType">消息类型</param>
		/// <return></return>
		public virtual int UpdateMsgType(long respId, string msgType, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[ResponseMessageLog] SET [MsgType]=@MsgType  WHERE [RespId]=@RespId";
			return AdoBase(sql)
							.AddInParameter("@MsgType", msgType != null ?  (object)msgType : DBNull.Value, DbType.AnsiString, 20)
							.AddInParameter("@RespId", respId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "respId">日志ID</param>
		/// <param name = "toUser">接收用户</param>
		/// <return></return>
		public virtual int UpdateToUser(long respId, string toUser)
		{
			return UpdateToUser(respId, toUser, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "respId">日志ID</param>
		/// <param name = "toUser">接收用户</param>
		/// <return></return>
		public virtual int UpdateToUser(long respId, string toUser, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[ResponseMessageLog] SET [ToUser]=@ToUser  WHERE [RespId]=@RespId";
			return AdoBase(sql)
							.AddInParameter("@ToUser", toUser != null ?  (object)toUser : DBNull.Value, DbType.AnsiString, 100)
							.AddInParameter("@RespId", respId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "respId">日志ID</param>
		/// <param name = "fromUser">来源用户</param>
		/// <return></return>
		public virtual int UpdateFromUser(long respId, string fromUser)
		{
			return UpdateFromUser(respId, fromUser, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "respId">日志ID</param>
		/// <param name = "fromUser">来源用户</param>
		/// <return></return>
		public virtual int UpdateFromUser(long respId, string fromUser, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[ResponseMessageLog] SET [FromUser]=@FromUser  WHERE [RespId]=@RespId";
			return AdoBase(sql)
							.AddInParameter("@FromUser", fromUser != null ?  (object)fromUser : DBNull.Value, DbType.AnsiString, 100)
							.AddInParameter("@RespId", respId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "respId">日志ID</param>
		/// <param name = "createTime">创建时间</param>
		/// <return></return>
		public virtual int UpdateCreateTime(long respId, DateTime? createTime)
		{
			return UpdateCreateTime(respId, createTime, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "respId">日志ID</param>
		/// <param name = "createTime">创建时间</param>
		/// <return></return>
		public virtual int UpdateCreateTime(long respId, DateTime? createTime, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[ResponseMessageLog] SET [CreateTime]=@CreateTime  WHERE [RespId]=@RespId";
			return AdoBase(sql)
							.AddInParameter("@CreateTime", createTime.HasValue ? (object)createTime.Value : DBNull.Value, DbType.DateTime, 8)
							.AddInParameter("@RespId", respId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "respId">日志ID</param>
		/// <param name = "respXml">响应文本</param>
		/// <return></return>
		public virtual int UpdateRespXml(long respId, string respXml)
		{
			return UpdateRespXml(respId, respXml, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "respId">日志ID</param>
		/// <param name = "respXml">响应文本</param>
		/// <return></return>
		public virtual int UpdateRespXml(long respId, string respXml, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[ResponseMessageLog] SET [RespXml]=@RespXml  WHERE [RespId]=@RespId";
			return AdoBase(sql)
							.AddInParameter("@RespXml", respXml != null ?  (object)respXml : DBNull.Value, DbType.String, -1)
							.AddInParameter("@RespId", respId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "respId">日志ID</param>
		/// <param name = "respTime">响应文本</param>
		/// <return></return>
		public virtual int UpdateRespTime(long respId, DateTime? respTime)
		{
			return UpdateRespTime(respId, respTime, null);
		}

		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name = "tm">事务管理对象</param>
		/// <param name = "respId">日志ID</param>
		/// <param name = "respTime">响应文本</param>
		/// <return></return>
		public virtual int UpdateRespTime(long respId, DateTime? respTime, TransactionManager tm = null)
		{
			const string sql = @"UPDATE [dbo].[ResponseMessageLog] SET [RespTime]=@RespTime  WHERE [RespId]=@RespId";
			return AdoBase(sql)
							.AddInParameter("@RespTime", respTime.HasValue ? (object)respTime.Value : DBNull.Value, DbType.DateTime, 8)
							.AddInParameter("@RespId", respId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}

		/// <summary>
		/// 按自定义条件更新数据
		/// </summary>
		/// <param name = "set">更新列</param>
		/// <param name = "where">更新条件</param>
		/// <param name = "paras">参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public int Update(string set, string where, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			if (string.IsNullOrEmpty(set)) throw new ArgumentNullException("set");
			var sql = string.Format(@"UPDATE [dbo].[ResponseMessageLog] SET {0} {1}", set, (string.IsNullOrEmpty(where) ? string.Empty : " WHERE " + where));
			return AdoBase(sql)
							.AddParameters(paras)
							.ExecuteNonQuery(tm);
		}
		#endregion

		#region Delete方法集合
		/// <summary>
		/// 按主键删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "respId">日志ID</param>
		public int DeleteByPK(long respId, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[ResponseMessageLog] WHERE [RespId]=@RespId";
			return AdoBase(sql)
							.AddInParameter("@RespId", respId, DbType.Int64, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "msgType">消息类型</param>
		public int DeleteByMsgType(string msgType, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[ResponseMessageLog] WHERE [MsgType]=@MsgType";
			return AdoBase(sql)
							.AddInParameter("@MsgType", msgType != null ?  (object)msgType : DBNull.Value, DbType.AnsiString, 20)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "toUser">接收用户</param>
		public int DeleteByToUser(string toUser, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[ResponseMessageLog] WHERE [ToUser]=@ToUser";
			return AdoBase(sql)
							.AddInParameter("@ToUser", toUser != null ?  (object)toUser : DBNull.Value, DbType.AnsiString, 100)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "fromUser">来源用户</param>
		public int DeleteByFromUser(string fromUser, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[ResponseMessageLog] WHERE [FromUser]=@FromUser";
			return AdoBase(sql)
							.AddInParameter("@FromUser", fromUser != null ?  (object)fromUser : DBNull.Value, DbType.AnsiString, 100)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "createTime">创建时间</param>
		public int DeleteByCreateTime(DateTime? createTime, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[ResponseMessageLog] WHERE [CreateTime]=@CreateTime";
			return AdoBase(sql)
							.AddInParameter("@CreateTime", createTime.HasValue ? (object)createTime.Value : DBNull.Value, DbType.DateTime, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "respXml">响应文本</param>
		public int DeleteByRespXml(string respXml, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[ResponseMessageLog] WHERE [RespXml]=@RespXml";
			return AdoBase(sql)
							.AddInParameter("@RespXml", respXml != null ?  (object)respXml : DBNull.Value, DbType.String, -1)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 按字段删除
		/// </summary>
		/// <param name="tm">事务管理对象</param>
		/// <param name = "respTime">响应文本</param>
		public int DeleteByRespTime(DateTime? respTime, TransactionManager tm = null)
		{
			const string sql = @"DELETE FROM [dbo].[ResponseMessageLog] WHERE [RespTime]=@RespTime";
			return AdoBase(sql)
							.AddInParameter("@RespTime", respTime.HasValue ? (object)respTime.Value : DBNull.Value, DbType.DateTime, 8)
							.ExecuteNonQuery(tm);
		}
		/// <summary>
		/// 删除指定条件的记录
		/// </summary>
		/// <param name = "whereClause">自定义删除条件，where子句。如：id=1 and name='aaa'</param>
		/// <param name = "paras">where子句中定义的参数集合</param>
		/// <param name="tm">事务管理对象</param>
		/// <return></return>
		public int Delete(string whereClause, IEnumerable<DbParameter> paras, TransactionManager tm = null)
		{
			var sql = string.Format(@"DELETE FROM [dbo].[ResponseMessageLog] {0}", (string.IsNullOrEmpty(whereClause) ? string.Empty : " WHERE " + whereClause));
			return AdoBase(sql)
							.AddParameters(paras)
							.ExecuteNonQuery(tm);
		}
		#endregion

		#region  自定义方法集合
		#endregion

	}


	#endregion
}
